<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sticky粘性定位 实现 吸附效果</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .ads-position {
      overflow: auto;
      position: relative;
      width: 400px;
      height: 280px;
      outline: 1px solid #3c9;
      margin: 30px auto;
    }
    ul{
        padding: 200px 0;
    }
    li {
        position: sticky;
        height: 40px;
        line-height: 40px;
        text-align: center;
        color: #fff;
    }
    li:nth-child(1) {
        top: 0;
        z-index: 9;
        background-color: #f66;
    }
    li:nth-child(2) {
        top: 40px;
        z-index: 9;
        background-color: #66f;
    }
    li:nth-child(3), li.normal {
        background-color: #f90;
    }
    li:nth-child(4) {
        bottom: 0;
        z-index: 9;
        background-color: #09f;
    }
    li:nth-child(5) {
        bottom: 40px;
        z-index: 9;
        background-color: #3c9;
    }
  </style>
</head>
<body>
  <div class="ads-position">
    <ul>
        <li>Top 1</li>
        <li>Top 2</li>
        <li class="normal">Normal</li>
        <li>Bottom 1</li>
        <li>Bottom 2</li>
        <li class="normal">Normal</li>
        <li class="normal">Normal</li>
        <li class="normal">Normal</li>
        <li class="normal">Normal</li>

    </ul>
  </div>
</body>
</html>
